<?php
/** .-------------------------------------------------------------------
* |  Software: [HDPHP framework]
* |      Site: www.hdphp.com
* |-------------------------------------------------------------------
* |    Author: 向军 <2300071698@qq.com>
* |    WeChat: aihoudun
* | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
* '-------------------------------------------------------------------*/

namespace system\model;

use hdphp\Model\Model;

class GoodsList extends Model{
	//数据表
	protected $table = "goods_list";

	//允许填充字段
	protected $allowFill = [ ];

	//禁止填充字段
	protected $denyFill = [ ];

	//完整表名
	protected $full = false;

	//自动验证
	protected $validate=[
		//['字段名','验证方法','提示信息',验证条件,验证时间],
        ['inventory','required','请填写库存',self::MUST_VALIDATE,self::MODEL_BOTH],
        ['number','required','请填写货号',self::MUST_VALIDATE,self::MODEL_BOTH]
	];


	//自动完成
	protected $auto=[
		//['字段名','处理方法','方法类型',验证条件,验证时机]
	];

	//自动过滤
    protected $filter=[
        //[表单字段名,过滤条件,处理时间]
    ];

	//时间操作,需要表中存在created_at,updated_at字段
	protected $timestamps=false;

    public function store(){
//	    $gid=Q('gid');
        $GoodsList=new GoodsList();
        $combine = Q('post.combine');

        foreach ($combine as $k=>$v){
            if(!$v){
                $this->error = '请选择相对应的规格';
                return false;
            }
        };
        $combine =implode(',',$combine);
        $data=Db::table('goods_list')->where('combine',$combine)->first();
        if($data){
            $this->error = '已存在';return false;
        }

        $GoodsList['combine']=$combine;
        $GoodsList['inventory']=Q('post.inventory');
        $GoodsList['number']=Q('post.number');
        $GoodsList['gid']=Q('gid');
        return $GoodsList->save();

    }

    public function edit(){
        $glid=Q('glid');
        $GoodsList=GoodsList::find($glid);
        $GoodsList['inventory']=Q('post.inventory');
        $GoodsList['number']=Q('post.number');
        return $GoodsList->save();
    }
}